package edu.hgnu.provider;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import edu.hgnu.enums.LogType;
import edu.hgnu.utils.RabbitMQUtils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * @author admin
 */
public class Provider {
    public static void main(String[] args) throws IOException {
        //获取连接对象
        Connection connection = RabbitMQUtils.getConnection();
        //获取连接通道对象
        String exchangeName = "logs_direct";
        Channel channel = connection.createChannel();
        //通过通道声明交换机，1，exchange：交换机名字；2：direct：路由模式
        channel.exchangeDeclare(exchangeName,"direct");
        //发送消息
        //String routingKey = "error";
        String routingKey = LogType.getValueByIndex(4);
        System.out.println(LogType.getValueByIndex(4)+"==>"+LogType.getTextByIndex(4));

        channel.basicPublish(exchangeName,routingKey,null,("这是基于direct模型发布的基于route key:"+routingKey+"发送的消息").getBytes(StandardCharsets.UTF_8));

        RabbitMQUtils.closeConnAndChanel(connection,channel);
    }
}
